package cetcbigdata.da.personal_service.hubei;

import cetcbigdata.da.base.Base;
import cetcbigdata.da.base.DownloadAndUploadMinio;
import com.alibaba.datax.common.plugin.RecordSender;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;

public class SpiderHB extends Base {

    private final static String region = "湖北省";

    private final static String module = "个人服务";

    @Override
    public void getData(RecordSender recordSender, List<Object> fieldsList) {

    }

    @Override
    public JSONObject getDataDemo() {
        try {
            return this.parseListPage();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    private JSONObject parseListPage(){
        try {
            int cs = 1;
            while (cs<=31) {
//              1.1对参数进行特殊化处理
                int currentPage = 1;
                int js = 5;
                js = js * cs;
                String subjectIdsGr = String.format("%03d", js);
                System.out.println(subjectIdsGr);
                //System.out.println("-----------------这是第"+cs+"次循环------------");
                ++cs;
                 // 1，2开始访问列表页
                String listUrl = "http://zwfw.hubei.gov.cn/web/bszn/item_project";
                JSONObject parmas = new JSONObject();
                parmas.put("serviceGr", "1");
                // System.out.println(cs);
                parmas.put("subjectIdsGr",subjectIdsGr);
                parmas.put("regionCode", "420000000000");
                parmas.put("areaGrade", "2");
                parmas.put("currentPage", currentPage);
                parmas.put("pageSize", "10");
                String listResponse = postFormReq(listUrl, new JSONObject(), parmas);
                JSONObject responseObj = JSONObject.parseObject(listResponse);
                // 获取总页数为翻页做准备
                int Page = responseObj.getJSONObject("data").getInteger("pages");

                for (;currentPage <= Page;) {
                    System.out.println("currentPage:"+currentPage);
                    System.out.println("page:"+Page);
                    // System.out.println("---------------打印jsonobject对象--------------------------------------");
                    // System.out.println(listResponse);
                    if (responseObj.getString("status").equals("200")) {
                        // System.out.println("--------------------打印jsonobject对象中records中的信息，获取一个项目中有多少个结点---------------------------------");
                        JSONArray list = responseObj.getJSONObject("data").getJSONArray("records");
                        // System.out.println("这是records"+list);
                        // 遍历一个页里有多少个大标签
                        for (Object o : list) {
                            //                        2.1 想要获取打开请求头的网页，就要先获取到post请求url的头部信息 先获取 TASKCODE
                            String item = ((JSONObject) o).getString("TASKCODE");
                            String TASKNAME = ((JSONObject) o).getString("TASKNAME");
                            System.out.println(item);
                           //                      2.2 想要获  取打开请求头的网页，就要 先获取到post请求url的头部信息      actionCode


                            String listUrlnext = "http://zwfw.hubei.gov.cn/web/tysl/ykypt/standard/transact/project/getActionByTaskCode";
                            JSONObject parmasnext = new JSONObject();
                            parmasnext.put("taskCode", item);
                            String listResponsenext = postFormReq(listUrlnext, new JSONObject(), parmasnext);
                            //                        2.2.3###出现了第二种情况 即是 actionCodelist为空的情况
                            JSONObject responseObjnext = JSONObject.parseObject(listResponsenext);
                            //会出现特殊使该数组不为1,
                            JSONArray actionCodelist = JSONArray.parseArray(responseObjnext.getString("data"));
                            if (!isNotBlankOrNull(actionCodelist)) {
                                System.out.println("错误查找");
                                // 直接获取当前网站的  TRANSACTCODE
                                String specialListUrl = "http://zwfw.hubei.gov.cn/web/bszn/item_project_transaction";
                                JSONObject SpecialParmasnext = new JSONObject();
                                // System.out.println(item);
                                SpecialParmasnext.put("taskcode", item);
                                SpecialParmasnext.put("currentPage", currentPage);
                                SpecialParmasnext.put("pageSize", "5");
                                String SpeciallistResponsenext = postFormReq(specialListUrl, new JSONObject(), SpecialParmasnext);
                                // System.out.println(SpeciallistResponsenext);
                                JSONObject SpecialresponseObj = JSONObject.parseObject(SpeciallistResponsenext);
                                JSONArray list2 = SpecialresponseObj.getJSONObject("data").getJSONArray("records");
                                for (int k = 0; k < list2.size(); k++) {
                                    JSONObject jsonObject2 = list2.getJSONObject(k);
                                    String TRANSACTCODE = jsonObject2.getString("TRANSACTCODE");
                                    // System.out.println("这是特殊网页的TRANSACTCODE"+TRANSACTCODE);
                                    // 开始获取详情页的信息
                                    String specialdetailurl = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
                                    JSONObject specialdetailparmas1 = new JSONObject();
                                    specialdetailparmas1.put("transactCode", TRANSACTCODE);
                                    specialdetailparmas1.put("type", "legalbasis");
                                    String specialdetailResponse = postFormReq(specialdetailurl, new JSONObject(), specialdetailparmas1);
                            //      System.out.println(detailResponse);
                                    JSONObject content = this.parseDetailPage1(specialdetailResponse);
                                    return content;

                                }

                            }
                            else {
                                for (int i = 0; i < actionCodelist.size(); i++) {
                                    JSONObject jsonObject1 = actionCodelist.getJSONObject(i);
                                    String actionCode = jsonObject1.getString("actionCode");
                                    // 访问下一个子网页 获取 TransactCode
                                    String listurl2 = "http://zwfw.hubei.gov.cn/web/tysl/ykypt/standard/item/transact/selectPageList";
                                    JSONObject parmasnext2 = new JSONObject();
                                    parmasnext2.put("taskCode",item);
                                    parmasnext2.put("actionCode", actionCode);
                                    String listResponsenext2 = postFormReq(listurl2, new JSONObject(), parmasnext2);
                                    JSONObject responseObjnext2 = JSONObject.parseObject(listResponsenext2);
                                    JSONObject TransactCodefirst = JSONObject.parseObject(responseObjnext2.getString("data"));
                                    String error = TransactCodefirst.getString("error");
                                    if(StringUtils.isBlank(error)) {
                                        JSONObject bigobject = new JSONObject();
                                        List<JSONObject> detaillist = new ArrayList<>();
                                        JSONArray TransactCodefirstlist = TransactCodefirst.getJSONArray("data");
                                        for (int j = 0; j < TransactCodefirstlist.size(); j++) {
                                            JSONObject jsonObject2 = TransactCodefirstlist.getJSONObject(j);
                                            String TransactCode = jsonObject2.getString("TransactCode");
                                            //                            3.1现在开始解析详情页



                                            JSONObject detailmessage = new JSONObject();


                                            String detailUrl = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
                                            JSONObject detailparmas1 = new JSONObject();
                                            detailparmas1.put("transactCode", TransactCode);
                                            detailparmas1.put("type", "legalbasis");
                                            String detailResponse = postFormReq(detailUrl, new JSONObject(), detailparmas1);
                                            JSONObject content = this.parseDetailPage1(detailResponse);
                                            detailmessage.put("设定依据",content);

                                            JSONObject detailparmas2 = new JSONObject();
                                            detailparmas2.put("transactCode", TransactCode);
                                            detailparmas2.put("type", "handlingprocess");
                                            detailResponse = postFormReq(detailUrl, new JSONObject(), detailparmas2);
                                            content = this.parseDetailPage2(detailResponse);
                                            detailmessage.put("办理流程",content);



                                            JSONObject detailparmascondition = new JSONObject();
                                            detailparmascondition.put("transactCode", TransactCode);
                                            detailparmascondition.put("type", "condition");
                                            detailResponse = postFormReq(detailUrl, new JSONObject(), detailparmascondition);
                                            content = this.parseDetailPagecondition(detailResponse,TransactCode,subjectIdsGr);;
                                            detailmessage.put("受理条件",content);

                                            List<JSONObject> midobject = new ArrayList<>();

                                            JSONObject detailinfoExt=new JSONObject();
                                            detailinfoExt.put("transactCode", TransactCode);
                                            detailinfoExt.put("type", "infoExt");
                                            detailResponse = postFormReq(detailUrl, new JSONObject(), detailinfoExt);
                                            content = this.parseDetailinfoExt(detailResponse,TransactCode);
                                            midobject.add(content);
                                            //detailmessage.put("基本信息",content);

                                            JSONObject detaildocument=new JSONObject();
                                            detaildocument.put("transactCode", TransactCode);
                                            detaildocument.put("type", "document");
                                            detailResponse = postFormReq(detailUrl, new JSONObject(), detaildocument);
                                            content = this.parseDetaildocument(detailResponse);
                                            midobject.add(content);
                                            //detailmessage.put("审批结果信息",content);


                                            content = this.parseDetailbanlixinxi(TransactCode);
                                            midobject.add(content);
                                            //detailmessage.put("办理信息",content);


                                            content = this.parseDetailqitaxinxi(TransactCode);
                                            midobject.add(content);
                                            //detailmessage.put("其他信息",content);

                                            detailmessage.put("基本信息",midobject);

                                            content = this.parseDetailchuankoubanli(TransactCode);
                                            detailmessage.put("窗口办理",content);


                                            content = this.parseDetailshenqingtiaojian(TransactCode);
                                            detailmessage.put("申请条件",content);

                                            content = this.parseDetailxukeshoufei();
                                            detailmessage.put("许可收费",content);

                                            content = this.parseDetailzhongjiefuwu(TransactCode);
                                            detailmessage.put("中介服务",content);

                                            detaillist.add(detailmessage);

                                        }
                                        bigobject.put("选项",detaillist);
                                        bigobject.put("名称",TASKNAME);
                                        System.out.println(bigobject);
                                        return processResult(
                                                listUrl, listResponse,
                                                listurl2, listResponsenext2,
                                                bigobject, region, module
                                        );
                                    }
                                    else {
                                            System.out.println("该列表页没有详情页");
                                    }
                                }

                            }

                        }
                    }
                    ++currentPage;
                    JSONObject parmasnext = new JSONObject();
                    parmasnext.put("subjectIdsGr",subjectIdsGr);
                    parmasnext.put("regionCode", "420000000000");
                    parmasnext.put("areaGrade", "2");
                    parmasnext.put("currentPage", currentPage);
                    parmasnext.put("pageSize", "10");
                    listResponse = postFormReq(listUrl, new JSONObject(), parmasnext);
                    responseObj= JSONObject.parseObject(listResponse);
                }
    }
        } catch (Exception e) {
             e.printStackTrace();
        }
        return null;
    }
    //解析详情页
    private  JSONObject parseDetailPage1(String json){
        JSONObject NEW = new JSONObject();
        JSONObject detailobj = JSONObject.parseObject(json);
        JSONArray detaillist =JSONArray.parseArray(detailobj.getString("data"));
        List<JSONObject> list =new ArrayList<>();
        for(Object o:detaillist)
        {
                JSONObject res = new JSONObject();
                JSONObject object = new JSONObject();
                String NAME =  ((JSONObject)o).getString("NAME");
                res.put("号令",((JSONObject)o).getString("NUM"));
                res.put("颁布机构",((JSONObject)o).getString("IssueDept"));
                res.put("生效日期",((JSONObject)o).getString("EffectDay"));
                res.put("发布日期",((JSONObject)o).getString("EffectDay"));
                res.put("法规原文链接",((JSONObject)o).getString("Url"));
                res.put("条款内容",((JSONObject)o).getString("LawItems"));

                object.put(NAME,res);
                list.add(object);
        }
        NEW.put("文本",list);
        return NEW;
    }

    private  JSONObject parseDetailPage2(String json) throws IOException {
        JSONObject NEW = new JSONObject();
        JSONObject detailobj = JSONObject.parseObject(json);
        JSONArray detaillist =JSONArray.parseArray(detailobj.getString("data"));
        List<JSONObject> list =new ArrayList<>();
        String  specialType="";
        String  noExtendType="";
        StringBuffer strs = new StringBuffer();
        for(Object o:detaillist) {
            JSONObject object = new JSONObject();
            JSONObject res = new JSONObject();
               String NodeName = ((JSONObject) o).getString("NodeName");
                specialType = ((JSONObject) o).getString("SpecialType");
                if (specialType.equals("1")) {
                    specialType = "延长审批";
                } else if (specialType.equals("2")) {
                    specialType = "除延长审批之外的情况";
                } else {
                    specialType = "无";
                }
                res.put("审查标准", ((JSONObject) o).getString("CheckContent"));
                res.put("办理结果", ((JSONObject) o).getString("Result"));
                res.put("是否为特殊程序", IsSpecial(((JSONObject) o).getString("IsSpecial")));
                String NoExtendType = ((JSONObject) o).getString("NoExtendType");
                if (StringUtils.isBlank(NoExtendType)) {
                    noExtendType = "无";
                    res.put("特殊程序种类", noExtendType);
                } else {
                    String[] NoExtendTypelist = getNEType(NoExtendType);
                    for (String s : NoExtendTypelist) {
                        strs.append(s);
                        strs.append(",");
                    }
                    res.put("特殊程序种类", strs);
                }
                if (IsSpecial(((JSONObject) o).getString("IsSpecial")).equals("否")) {
                    specialType = "-";
                    noExtendType = "-";
                    res.put("特殊程序种类", noExtendType);
                }
                res.put("特殊程序类型", specialType);
                object.put(NodeName,res);
                list.add(object);
        }
        JSONObject handlingProceduresImage = new JSONObject();
        String orgImageUrl = "http://zwfw.hubei.gov.cn/web/lcfile/group1/M00/0A/35/wKhUBF-M_DKAQFglAAATYK0ceXw810.png";
        handlingProceduresImage.put("流程图原地址", orgImageUrl);
        handlingProceduresImage.put("minio地址", fileDownloadAndUploadMinioGet(orgImageUrl, "流程图.png"));
        NEW.put("办理流程图", handlingProceduresImage);
        NEW.put("文本",list);

        return NEW;
    }
    //获取特殊程序种类
    private String[] getNEType( String noExtendType) {
            String [] nett;
            nett = noExtendType.split(",");
            for (int i = 0; i < nett.length; i++) {

                switch (nett[i]) {
                    case "01":
                        nett[i] = "书面审查";
                        break;
                    case "02":
                        nett[i] = "实地核查";
                        break;
                    case "03":
                        nett[i] = "招标与拍卖";
                        break;
                    case "04":
                        nett[i] = "检验";
                        break;
                    case "05":
                        nett[i] = "检测";
                        break;
                    case "06":
                        nett[i] = "检疫";
                        break;
                    case "07":
                        nett[i] = "鉴定";
                        break;
                    case "08":
                        nett[i] = "考试";
                        break;
                    case "09":
                        nett[i] = "考核";
                        break;
                    case "10":
                        nett[i] = "专家评审";
                        break;
                    case "11":
                        nett[i] = "技术审查";
                        break;
                    case "12":
                        nett[i] = "听证";
                        break;
                    case "13":
                        nett[i] = "听取利害关系人意见";
                        break;
                    case "14":
                        nett[i] = "集体审查";
                        break;
                    case "15":
                        nett[i] = "法律法规或规章规定的其他审查方式";
                        break;
                }
            }
            return nett;

    }

    private String IsSpecial(String html)
    {
       if(html.equals("0"))
       {
           return "否";
       }
           return "是";
    }
    private  JSONObject parseDetailPagecondition(String json, String TransactCode,String subjectIdsGr){

        JSONObject detailobj = JSONObject.parseObject(json);
        JSONArray detaillist =JSONArray.parseArray(detailobj.getString("data"));
        JSONObject res = new JSONObject();
        for(Object o:detaillist) {
    //    先获取自己的当前网页的SubjectType
            String url = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
            JSONObject detailparmas = new JSONObject();
            detailparmas.put("transactCode", TransactCode);
            detailparmas.put("type", "subject");
            String Response = postFormReq(url,new JSONObject(),detailparmas);
            JSONObject content = JSONObject.parseObject(Response);
            JSONArray data = JSONObject.parseArray(content.getString("data"));
            String frzt="";
            String zrzt="";
            for (Object o1:data) {
                String SubjectType = ((JSONObject)o1).getString("SubjectType");
                if(StringUtils.isBlank(SubjectType)) {
                    frzt="";
                    zrzt="";

                }
                else
                {
                    if (data.size() > 1) {
                        if (SubjectType.equals("1")) {  //法人
                            subjectIdsGr = ((JSONObject) o1).getString("SubjectId");
                            frzt = getSxzt1(subjectIdsGr);

                        }
                        if (SubjectType.equals("0")) {
                            subjectIdsGr = ((JSONObject) o1).getString("SubjectId");
                            zrzt = getSxzt2(subjectIdsGr);

                        }
                    } else {

                        if (SubjectType.equals("1")) {  //法人
                            subjectIdsGr = ((JSONObject) o1).getString("SubjectId");
                            frzt = getSxzt1(subjectIdsGr);
                            zrzt = "无";
                        }
                        if (SubjectType.equals("0")) {
                            subjectIdsGr = ((JSONObject) o1).getString("SubjectId");
                            zrzt = getSxzt2(subjectIdsGr);
                            frzt = "无";
                        }
                    }
                }
            }
            res.put("面向法人事项主题",frzt);
            res.put("面向自然人事项主题",zrzt);
            url="http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
            detailparmas.put("transactCode", TransactCode);
            detailparmas.put("type", "info");
            Response = postFormReq(url,new JSONObject(),detailparmas);
            content = JSONObject.parseObject(Response);
            data = JSONObject.parseArray(content.getString("data"));
            StringBuffer strs = new StringBuffer();
            for(Object o1 :data) {
                String serviceCode = ((JSONObject)o1).getString("serviceCode");
                String []fwdx=getfwdx(serviceCode);
                for(String s:fwdx)
                {
                  strs.append(s);
                  strs.append(",");
                }

            }
            res.put("申请条件",((JSONObject)o).getString("AcceptCondition"));
            res.put("服务对象",strs);
        }
        return res;
    }
    //获取法人事项主题
    private String getSxzt1(String sxzt) {


            switch (sxzt) {
                case "005":
                    sxzt = "设立变更";
                    break;
                case "010":
                    sxzt = "准营准办";
                    break;
                case "015":
                    sxzt= "资质认证";
                    break;
                case "020":
                    sxzt= "年检年审";
                    break;
                case "025":
                    sxzt= "税收财务";
                    break;
                case "030":
                    sxzt = "人力资源";
                    break;
                case "035":
                    sxzt = "社会保障";
                    break;
                case "040":
                    sxzt = "投资审批";
                    break;
                case "045":
                    sxzt= "融资信贷";
                    break;
                case "050":
                    sxzt = "抵押质押";
                    break;
                case "055":
                    sxzt = "商务贸易";
                    break;
                case "060":
                    sxzt = "招标拍卖";
                    break;
                case "065":
                    sxzt = "海关口岸";
                    break;
                case "070":
                    sxzt = "涉外服务";
                    break;
                case "075":
                    sxzt = "农林牧渔";
                    break;
                case "085":
                    sxzt = "国土和规划建设";
                    break;
                case "090":
                    sxzt = "交通运输";
                    break;
                case "095":
                    sxzt = "环保绿化";
                    break;
                case "100":
                    sxzt = "应对气候变化";
                    break;
                case "105":
                    sxzt = "水务气象";
                    break;
                case "110":
                    sxzt = "医疗卫生";
                    break;
                case "115":
                    sxzt = "科技创新";
                    break;
                case "120":
                    sxzt = "文体教育";
                    break;
                case "125":
                    sxzt = "知识产权";
                    break;
                case "130":
                    sxzt = "民族宗教";
                    break;
                case "135":
                    sxzt = "质量技术";
                    break;
                case "140":
                    sxzt = "检验检疫";
                    break;
                case "145":
                    sxzt = "安全生产";
                    break;
                case "150":
                    sxzt = "公安消防";
                    break;
                case "155":
                    sxzt = "司法公证";
                    break;
                case "160":
                    sxzt = "公用事业";
                    break;
                case "165":
                    sxzt = "法人注销";
                    break;
                case "170":
                    sxzt = "档案文物";
                    break;
                case "998":
                    sxzt= "地方特色分类";
                    break;
                case "999":
                    sxzt= "其他";
                    break;
            }

        return sxzt;
    }
    //获取自然人事项主题
    private String getSxzt2(String sxzt) {

            switch (sxzt) {
                case "005":
                    sxzt = "生育收养";
                    break;
                case "010":
                    sxzt = "户籍办理";
                    break;
                case "015":
                    sxzt = "民族宗教";
                    break;
                case "020":
                    sxzt = "教育科研";
                    break;
                case "025":
                    sxzt = "入伍服役";
                    break;
                case "030":
                    sxzt= "就业创业";
                    break;
                case "035":
                    sxzt= "设立变更";
                    break;
                case "040":
                    sxzt = "准营准办";
                    break;
                case "045":
                    sxzt = "抵押质押";
                    break;
                case "050":
                    sxzt = "职业资格";
                    break;
                case "055":
                    sxzt = "行政缴费";
                    break;
                case "060":
                    sxzt = "婚姻登记";
                    break;
                case "065":
                    sxzt = "优待抚恤";
                    break;
                case "070":
                    sxzt = "规划建设";
                    break;
                case "075":
                    sxzt = "住房保障";
                    break;
                case "085":
                    sxzt = "社会保障（社会保险、社会救助）";
                    break;
                case "090":
                    sxzt = "证件办理";
                    break;
                case "095":
                    sxzt = "交通出行";
                    break;
                case "100":
                    sxzt = "旅游观光";
                    break;
                case "105":
                    sxzt = "出境入境";
                    break;
                case "110":
                    sxzt = "消费维权";
                    break;
                case "115":
                    sxzt = "公共安全";
                    break;
                case "120":
                    sxzt = "司法公证";
                    break;
                case "125":
                    sxzt = "知识产权";
                    break;
                case "130":
                    sxzt = "环保绿化";
                    break;
                case "135":
                    sxzt= "文化体育";
                    break;
                case "140":
                    sxzt = "公用事业";
                    break;
                case "145":
                    sxzt = "医疗卫生";
                    break;
                case "150":
                    sxzt = "离职退休";
                    break;
                case "155":
                    sxzt = "死亡殡葬";
                    break;

            }

        return sxzt;
    }
//    获取服务对象
    private String[] getfwdx(String fwdx) {
//        "serviceCode\":\"1,2,3,4,9,5,6\
        String[] sites;
        sites = fwdx.split(",");
        for (int i = 0; i < sites.length; i++) {
            switch (sites[i]) {
                case "1":
                    sites[i] = "自然人";
                    break;
                case "2":
                    sites[i] = "企业法人";
                    break;
                case "3":
                    sites[i] = "事业法人";
                    break;
                case "4":
                    sites[i] = "社会组织法人";
                    break;
                case "5":
                    sites[i] = "非法人企业";
                    break;
                case "6":
                    sites[i] = "行政机关";
                    break;
                case "9":
                    sites[i] = "其他组织";
                    break;
            }
        }
        return sites;
    }

    private  JSONObject parseDetailinfoExt(String json,String TransactCode) {
        JSONObject detailobj = JSONObject.parseObject(json);
        JSONArray detaillist =JSONArray.parseArray(detailobj.getString("data"));
        JSONObject object = new JSONObject();
        JSONObject res = new JSONObject();
        for(Object o:detaillist) {
            res.put("事项名称", ((JSONObject)o).getString("TransactName"));
            res.put("实施编码", ((JSONObject)o).getString("TaskCode"));
            res.put("业务编码", ((JSONObject)o).getString("TransactCode"));
            res.put("基本编码", ((JSONObject)o).getString("CatalogCode"));
            res.put("受理机构", ((JSONObject)o).getString("DeptName"));
            res.put("办理类型", ProjectType(((JSONObject)o).getString("ProjectType")));
            JSONObject detailparmas = new JSONObject();

            //打开新的JSPC获取所需要的信息
            String url = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
            detailparmas.put("transactCode", TransactCode);
            detailparmas.put("type", "info");
            String Response = postFormReq(url,new JSONObject(),detailparmas);
            JSONObject content = JSONObject.parseObject(Response);
            JSONArray data = JSONObject.parseArray(content.getString("data"));
            String AnticipateDay="";
            String TransactionUseLevel="";
            for (Object o2:data) {
                String TaskType = ((JSONObject)o2).getString("TaskType");
                res.put("事项类型",getTaskType(TaskType));
                AnticipateDay = ((JSONObject)o2).getString("AnticipateDay");
                TransactionUseLevel = ((JSONObject)o2).getString("TransactionUseLevel");
            }
            AnticipateDay = AnticipateDay + "个工作日";
            res.put("法定办结时限", AnticipateDay);
            String PromiseDay = ((JSONObject)o).getString("PromiseDay");
            PromiseDay = PromiseDay + "个工作日";
            res.put("承诺办结时限", PromiseDay);

//            ---------------------------------------------
            detailparmas.put("transactCode", TransactCode);
            detailparmas.put("type", "window");
            Response = postFormReq(url,new JSONObject(),detailparmas);
            content = JSONObject.parseObject(Response);
            data = JSONObject.parseArray(content.getString("data"));
            String NetworkDepth="";
            for (Object o1:data)
            {
                NetworkDepth= ((JSONObject)o1).getString("NetworkDepth");
            }
            String []NetworkDepthlist=getWbsd(NetworkDepth);
            StringBuffer strs = new StringBuffer();
            for(String s:NetworkDepthlist)
            {
                strs.append(s);
                strs.append(",");
            }
            res.put("网办深度",strs);
            if(StringUtils.isBlank(TransactionUseLevel)){
               String UseLevel =  ((JSONObject)o).getString("UseLevel");
               if (StringUtils.isBlank(UseLevel))
               {
                   res.put("行使层级","无");

               }
               else {
                   String[] UseLevellist = getxscj(UseLevel);
                   StringBuffer useLevel = new StringBuffer();
                   for (String s : UseLevellist) {
                       useLevel.append(s);
                       useLevel.append(",");
                   }
                   res.put("行使层级", useLevel);
               }
            }
            else {
                String [] TUseLevellist=getxscj(TransactionUseLevel);
                StringBuffer TUseLevel = new StringBuffer();
                for(String s:TUseLevellist)
                {
                    TUseLevel.append(s);
                    TUseLevel.append(",");
                }
                res.put("行使层级",TUseLevel);
            }
         if(StringUtils.isBlank(((JSONObject)o).getString("EntrustName")))
         {
             res.put("委托部门","无");
         }else {
             res.put("委托部门",((JSONObject)o).getString("EntrustName"));
         }
         String PowerSource =  ((JSONObject)o).getString("PowerSource");
         if(StringUtils.isBlank(PowerSource))
         {
             res.put("权利来源","无");
         }
         else
         {
             PowerSource = getPowerSource(PowerSource);
             res.put("权利来源",PowerSource);
         }

        }
        return res;

    }
    //获取事项类型
    private String getTaskType(String tasktp) {
        switch (tasktp) {
            case "01":
                tasktp = "行政许可";
                break;
            case "02":
                tasktp = "行政处罚";
                break;
            case "03":
                tasktp = "行政强制";
                break;
            case "04":
                tasktp = "行政征收";
                break;
            case "05":
                tasktp = "行政给付";
                break;
            case "06":
                tasktp = "行政检查";
                break;
            case "07":
                tasktp = "行政确认";
                break;
            case "08":
                tasktp = "行政奖励";
                break;
            case "09":
                tasktp = "行政裁决";
                break;
            case "10":
                tasktp = "其他行政权力";
                break;
            case "20":
                tasktp = "公共服务";
                break;
        }
        return tasktp;
    }
    private String ProjectType (String json)
{
    if(StringUtils.isBlank(json)){
        json="无";
    }
    else if(json.equals("1"))
    {
        json="即办件";
    }
    else {
        json="承诺件";
    }
    return json;
}
    //网办深度
    private String[] getWbsd(String wbsd) {

        String[] fwdxArr = wbsd.split(",");
        for (int i = 0; i < fwdxArr.length; i++) {
            switch (fwdxArr[i]) {
                case "1":
                    fwdxArr[i] = "互联网咨询";
                    break;
                case "2":
                    fwdxArr[i] = "互联网收件";
                    break;
                case "3":
                    fwdxArr[i] = "互联网预审";
                    break;
                case "4":
                    fwdxArr[i] = "互联网受理";
                    break;
                case "5":
                    fwdxArr[i] = "互联网办理";
                    break;
                case "6":
                    fwdxArr[i] = "互联网办理结果信息反馈";
                    break;
                case "7":
                    fwdxArr[i] = "互联网电子证照反馈";
                    break;
                case "9":
                    fwdxArr[i] = "其他";
                    break;
                default:
                    fwdxArr[i] = "无";
                    break;
            }
        }
        return fwdxArr;
    }

    private String[] getxscj(String xscj){
        String[] xscjArr = xscj.split(",");
        for (int i = 0; i < xscjArr.length; i++) {
            switch (xscjArr[i]) {
                case "1":
                    xscjArr[i] = "国家级";
                    break;
                case "2":
                    xscjArr[i] = "省级";
                    break;
                case "3":
                    xscjArr[i] = "市级";
                    break;
                case "4":
                    xscjArr[i] = "县区级";
                    break;
                case "5":
                    xscjArr[i] = "乡镇级";
                    break;
                case "6":
                    xscjArr[i] = "村级";
                    break;
            }
        }
        return xscjArr;
    }
    //权力来源
    private  String getPowerSource(String qlly) {
            switch (qlly) {
                case "1":
                    qlly = "法定本级行使";
                    break;
                case "2":
                    qlly= "上级下放";
                    break;
                case "3":
                    qlly = "上级授权";
                    break;
                case "4":
                    qlly = "同级授权";
                    break;
                case "5":
                    qlly = "上级委托";
                    break;
                case "6":
                    qlly = "同级委托";
                    break;

        }
        return qlly;
    }

    private  JSONObject parseDetaildocument(String json) throws IOException {
        JSONObject detailobj = JSONObject.parseObject(json);
        JSONArray detaillist =JSONArray.parseArray(detailobj.getString("data"));
        JSONObject object = new JSONObject();
        JSONObject res = new JSONObject();
            for (Object o : detaillist) {
//                if (detaillist.size() == 1&&!StringUtils.isBlank(((JSONObject)o).getString("message"))) {
//                    res.put("审批结果名称", "");
//                    res.put("审批结果类型", "无");
//                    res.put("不准予结果名称", "");
//                    res.put("不准予结果名称", "无");
//                    res.put("审批结果", "无");
//                    res.put("审批结果", "无");
//                }
                String isnot =((JSONObject)o).getString("isnot");
                if((!StringUtils.isBlank(isnot)) && isnot.equals("0")){
                    String AllowName=((JSONObject)o).getString("AllowName");
                    if(!StringUtils.isBlank(AllowName))
                    {
                        //
                        String samplePath =((JSONObject)o).getString("samplePath");
                        if(StringUtils.isBlank(samplePath)) {
                            res.put("审批结果",AllowName);
                        }
                        else
                        {
                            JSONObject handlingProceduresImage = new JSONObject();
                            String orgImageUrl = "http://zwfw.hubei.gov.cn/web/lcfile/" + samplePath;
                            handlingProceduresImage.put("准许下载样本原地址", orgImageUrl);
                            handlingProceduresImage.put("minio地址", downLoadFileUpLoadMinio(orgImageUrl, "下载样本.png"));
                            handlingProceduresImage.put("文本",AllowName);
                            res.put("审批结果",handlingProceduresImage);
                        }
                    }
                    else {res.put("审批结果","");}

                   String AllowType=((JSONObject)o).getString("AllowType");
                    if(!StringUtils.isBlank(AllowType))
                    {
                        AllowType=getType(AllowType);
                        res.put("审批结果类型", AllowType);
                    }
                   else {res.put("审批结果类型","无");}
                    if(detaillist.size()==1)
                    {
                     res.put("不准予结果名称","无");
                     res.put("不准予结果类型","无");
                     res.put("不予审批结果","无");
                    }

                }
                else{
                    String NotAllowedSample =((JSONObject)o).getString("NotAllowedSample");
                    String NotAllowedName=((JSONObject)o).getString("NotAllowedName");
                    if(!StringUtils.isBlank(NotAllowedName)) {
                        if(StringUtils.isBlank(NotAllowedSample) || NotAllowedSample.equals("undefined/undefined")){
                            res.put("审批不通过结果",NotAllowedName);
                        }
                        else
                        {
                            JSONObject handlingProceduresImage = new JSONObject();
                            String orgImageUrl = "http://zwfw.hubei.gov.cn/web/lcfile/" + NotAllowedSample;
                            handlingProceduresImage.put("下载样本原地址", orgImageUrl);
                            handlingProceduresImage.put("minio地址", downLoadFileUpLoadMinio(orgImageUrl, "下载样本.png"));
                            handlingProceduresImage.put("文本",NotAllowedName);
                            res.put("审批不通过结果",handlingProceduresImage);
                        }
                    }
                    else{ res.put("审批不通过结果","");}
                    String NotAllowedType = ((JSONObject)o).getString("NotAllowedName");
                    if(StringUtils.isBlank(NotAllowedType))
                    {
                        res.put("审批不通过结果类型","无");
                    }
                    else{NotAllowedType=getType(NotAllowedType);
                        res.put("审批不通过结果类型",NotAllowedType);}

                    if (detaillist.size() == 1) {
                        res.put("审批结果名称","无");
                        res.put("准予许可结果类型","无");
                    }
                }
            }


        return res;
    }
    //审批结果
    private String getType(String spjg) {
        switch (spjg) {
            case "1":
                spjg = "证明";
                break;
            case "2":
                spjg = "证照";
                break;
            case "4":
                spjg = "批文";
                break;
            case "9":
                spjg = "其他";
                break;
            case "99":
                spjg = "无";
                break;
            default:
                spjg = "无";
                break;
        }
        return spjg;
    }

    private  JSONObject parseDetailbanlixinxi(String TransactCode) {
        JSONObject object = new JSONObject();
        JSONObject res = new JSONObject();
        String detailUrl = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
        JSONObject detailparmas1 = new JSONObject();
        detailparmas1.put("transactCode", TransactCode);
        detailparmas1.put("type", "infoExt");
        String detailResponse = postFormReq(detailUrl, new JSONObject(), detailparmas1);
        JSONObject detailobj = JSONObject.parseObject(detailResponse);
        JSONArray detaillist = JSONArray.parseArray(detailobj.getString("data"));
        for (Object o : detaillist) {   //res.put("标题",((JSONObject)o).getString("NAME"));
            String HandleArea = ((JSONObject) o).getString("HandleArea");
            if (StringUtils.isBlank(HandleArea)) {
                res.put("通办范围", "无");
            } else {
                res.put("通办范围", getHandleArea(HandleArea));
            }
            String IsCloseToHome = ((JSONObject) o).getString("IsCloseToHome");
            if (IsCloseToHome.equals("1")) {
                res.put("是否就近办理", "是");
            } else {
                res.put("是否就近办理", "否");
            }
            String HandleForm = ((JSONObject) o).getString("HandleForm");
            if (StringUtils.isBlank(HandleForm)) {
                res.put("办理形式", "无");
            } else {
                StringBuffer strs = new StringBuffer();
                String[] fwdx = getBLstyle(HandleForm);
                for (String s : fwdx) {
                    strs.append(s);
                    strs.append(",");
                }

                res.put("办理形式", strs);
            }

        }
        detailUrl = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
        detailparmas1 = new JSONObject();
        detailparmas1.put("transactCode", TransactCode);
        detailparmas1.put("type", "info");
        detailResponse = postFormReq(detailUrl, new JSONObject(), detailparmas1);
        detailobj = JSONObject.parseObject(detailResponse);
        detaillist = JSONArray.parseArray(detailobj.getString("data"));
        for (Object o : detaillist)
        {
            String IsOnline = ((JSONObject)o).getString("IsOnline");
            if(IsOnline.equals("1"))
            {
                res.put("是否网办","是");
            }
            else {res.put("是否网办","否");}
        }
        res.put("网办地址","http://zwfw.hubei.gov.cn");
        detailUrl = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
        detailparmas1 = new JSONObject();
        detailparmas1.put("transactCode", TransactCode);
        detailparmas1.put("type", "window");
        detailResponse = postFormReq(detailUrl, new JSONObject(), detailparmas1);
        detailobj = JSONObject.parseObject(detailResponse);
        detaillist = JSONArray.parseArray(detailobj.getString("data"));
        for (Object o : detaillist)
        {
            String IsSchedule = ((JSONObject)o).getString("IsSchedule");
            if(IsSchedule.equals("1"))
            {
                res.put("是否支持网上预约办理","支持");
            }
            else {res.put("是否支持网上预约办理","不支持");}
        }

        return res;
    }
    //通办范围
    private String getHandleArea(String ha) {
        switch (ha) {
            case "1":
                ha = "全国";
                break;
            case "2":
                ha = "全省";
                break;
            case "3":
                ha = "全市";
                break;
            case "4":
                ha = "全县";
                break;
            case "5":
                ha = "全镇(乡、街道)";
                break;
            case "6":
                ha = "跨村(社区)";
                break;
        }
        return ha;
    }

    //获取办理形式
    private String[] getBLstyle(String blstr) {
        String [] blArr = blstr.split(",");
        for (int i = 0; i < blArr.length; i++) {
            switch (blArr[i]) {
                case "1":
                    blArr[i] = "窗口办理";
                    break;
                case "2":
                    blArr[i] = "网上办理";
                    break;
                case "3":
                    blArr[i] = "快递申请";
                    break;
            }
        }
        return blArr;
    }


    private JSONObject parseDetailqitaxinxi(String TransactCode)
    {
        JSONObject object = new JSONObject();
        JSONObject res = new JSONObject();
        String detailUrl = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
        JSONObject detailparmas1 = new JSONObject();
        detailparmas1.put("transactCode", TransactCode);
        detailparmas1.put("type", "infoExt");
        String detailResponse = postFormReq(detailUrl, new JSONObject(), detailparmas1);
        JSONObject detailobj = JSONObject.parseObject(detailResponse);
        JSONArray detaillist = JSONArray.parseArray(detailobj.getString("data"));
        for (Object o:detaillist)
        {
            String OtherDept = ((JSONObject) o).getString("OtherDept");
            if(StringUtils.isBlank(OtherDept)){
                res.put("联办机构","无");
            }
            else{
                res.put("联办机构",OtherDept);
            }
            String LimitExplain = ((JSONObject) o).getString("LimitExplain");
            if(StringUtils.isBlank(LimitExplain))
            {res.put("数量限制","无");}
            else{res.put("数量限制",LimitExplain);}

        }
        detailUrl = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
        detailparmas1 = new JSONObject();
        detailparmas1.put("transactCode", TransactCode);
        detailparmas1.put("type", "window");
        detailResponse = postFormReq(detailUrl, new JSONObject(), detailparmas1);
        detailobj = JSONObject.parseObject(detailResponse);
        detaillist = JSONArray.parseArray(detailobj.getString("data"));
        for (Object o:detaillist)
        {
            String IsServiceTerminals = ((JSONObject) o).getString("IsServiceTerminals");
            if(IsServiceTerminals.equals("1"))
            {res.put("自助终端办理","支持");}
            else{res.put("自助终端办理","不支持");}
            String IsMobileTerminal = ((JSONObject) o).getString("IsMobileTerminal");
            if(IsMobileTerminal.equals("1"))
            {res.put("移动端形式","支持");}
            else {res.put("移动端形式","不支持");}
            String MobileTerminalDepth = ((JSONObject) o).getString("MobileTerminalDepth");
            if(StringUtils.isBlank(MobileTerminalDepth) || MobileTerminalDepth.equals("[]")) {
                res.put("移动服务内容","无");
            }
            else {
                StringBuffer strs = new StringBuffer();
                String[] fwdx = getAppDepth(MobileTerminalDepth);
                for (String s : fwdx) {
                    strs.append(s);
                    strs.append(",");
                }
                res.put("移动服务内容", strs);
            }

        }
        detailUrl = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
        detailparmas1 = new JSONObject();
        detailparmas1.put("transactCode", TransactCode);
        detailparmas1.put("type", "country");
        detailResponse = postFormReq(detailUrl, new JSONObject(), detailparmas1);
        detailobj = JSONObject.parseObject(detailResponse);
        detaillist = JSONArray.parseArray(detailobj.getString("data"));
        for (Object o :detaillist)
        {
           String AppIsSingleLogin = ((JSONObject) o).getString("AppIsSingleLogin");
           if(StringUtils.isBlank(AppIsSingleLogin) || !AppIsSingleLogin.equals("1"))
           {
               res.put("移动端是否对接单点登录","否");
           }
           else {res.put("移动端是否对接单点登录","是");}
           String MobileTerminalUrl = ((JSONObject) o).getString("MobileTerminalUrl");
           if(StringUtils.isBlank(MobileTerminalUrl) || !MobileTerminalUrl.equals("1"))
           {
                res.put("移动端是否对接单点登录","否");
           }
            else {res.put("移动端是否对接单点登录","是");}
        }
        res.put("移动端办理地址","无");
        res.put("计算机端是否对接单点登录","无");
        res.put("计算机端办理地址","无");
        res.put("是否支持网上支付","不支持");
        res.put("是否信用监督","无");
        res.put("是否年审年检","无");
        res.put("是否物流","无");
        return res;
    }

    //获取移动端服务内容
    private String[] getAppDepth(String AppDepth) {
        String [] AppDepthArr = AppDepth.split(",");
        for (int i = 0; i < AppDepthArr.length; i++) {
            switch (AppDepthArr[i]) {
                case "1":
                    AppDepthArr[i] = "预约";
                    break;
                case "2":
                    AppDepthArr[i] = "查询";
                    break;
                case "3":
                    AppDepthArr[i] = "办理";
                    break;
                case "4":
                    AppDepthArr[i] = "评价";
                    break;
            }
        }
        return AppDepthArr;
    }

    private JSONObject parseDetailchuankoubanli(String TransactCode){
        JSONObject res = new JSONObject();
        String detailUrl = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
        JSONObject detailparmas1 = new JSONObject();
        detailparmas1.put("transactCode", TransactCode);
        detailparmas1.put("type", "window");
        String detailResponse = postFormReq(detailUrl, new JSONObject(), detailparmas1);
        JSONObject detailobj = JSONObject.parseObject(detailResponse);
        JSONArray detaillist = JSONArray.parseArray(detailobj.getString("data"));
        for(Object o:detaillist)
        {
            String EnterHall = ((JSONObject) o).getString("EnterHall");
            if(StringUtils.isBlank(EnterHall) || !EnterHall.equals("1")){
                res.put("是否进驻服务大厅","否");
            }
            else { res.put("是否进驻服务大厅","是");}
            String NAME = ((JSONObject) o).getString("NAME");
            if(StringUtils.isBlank(NAME))
            {res.put("办事大厅名称","无");}
            else {res.put("办事大厅名称",NAME);}

            String OfficeHour = ((JSONObject) o).getString("OfficeHour");
            if(StringUtils.isBlank(OfficeHour))
            {res.put("办理时间","无");}
            else {res.put("办理时间",OfficeHour);}

            String ADDRESS = ((JSONObject) o).getString("ADDRESS");
            if(StringUtils.isBlank(ADDRESS))
            {res.put("办理地点","无");}
            else {res.put("办理地点", ADDRESS);}

            String TransactWindow = ((JSONObject) o).getString("TransactWindow");
            if(StringUtils.isBlank(TransactWindow))
            {res.put("办理窗口","无");}
            else {res.put("办理窗口", TransactWindow);}

            String PHONE = ((JSONObject) o).getString("PHONE");
            if(StringUtils.isBlank(PHONE))
            {res.put("办公电话","无");}
            else {res.put("办公电话", PHONE);}
//            "http://zwfw.hubei.gov.cn/web/lcfile/"

            String MapImage = ((JSONObject) o).getString("MapImage");
            if(StringUtils.isBlank(MapImage) || MapImage.equals("undefined/undefined"))
            {res.put("办理地点地图","无");}
            else {
                JSONObject handlingProceduresImage = new JSONObject();
                String orgImageUrl = "http://zwfw.hubei.gov.cn/web/lcfile/" + MapImage;
                handlingProceduresImage.put("下载样本原地址", orgImageUrl);
                handlingProceduresImage.put("minio地址", downLoadFileUpLoadMinio(orgImageUrl, "办理地点地图.png"));
                res.put("办理地点地图", handlingProceduresImage);
                }
           String TrafficGuide = ((JSONObject) o).getString("TrafficGuide");
           String MetroGuide = ((JSONObject) o).getString("MetroGuide");
           if(StringUtils.isBlank(TrafficGuide))
           {
               if(StringUtils.isBlank(MetroGuide))
               {
                   res.put("公交","无");
                   res.put("地铁","无");

               }
               res.put("公交","无");
               res.put("地铁",MetroGuide);
           }
            res.put("公交",TrafficGuide);
            res.put("地铁",MetroGuide);

            String HandlingTimes = ((JSONObject) o).getString("HandlingTimes");
            if(!StringUtils.isBlank(HandlingTimes))
            {
                switch (HandlingTimes) {
                    case "1":
                        HandlingTimes = "跑一次";
                        break;
                    case "2":
                        HandlingTimes = "跑多次";
                        break;
                    case "0":
                        HandlingTimes = "跑零次";
                        break;
                }
                res.put("到办事现场次数",HandlingTimes);
            }
            res.put("到办事现场次数","");
            String LimitSceneExplain = ((JSONObject) o).getString("LimitSceneExplain");
            if(StringUtils.isBlank(LimitSceneExplain))
            {
                res.put("必须现场办理原因说明","无");
            }
            res.put("必须现场办理原因说明",LimitSceneExplain);
        }
        return res;

    }

    private JSONObject parseDetailshenqingtiaojian(String TransactCode) {
        JSONObject NEW = new JSONObject();
        List<JSONObject> list =new ArrayList<>();

        String detailUrl = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
        JSONObject detailparmas1 = new JSONObject();
        detailparmas1.put("transactCode", TransactCode);
        detailparmas1.put("type", "material");
        String detailResponse = postFormReq(detailUrl, new JSONObject(), detailparmas1);
        JSONObject detailobj = JSONObject.parseObject(detailResponse);
        JSONArray detaillist = JSONArray.parseArray(detailobj.getString("data"));
        for (Object o:detaillist) {
            JSONObject res = new JSONObject();
            JSONObject object = new JSONObject();
            String alias = ((JSONObject) o).getString("alias");
            String materialType = ((JSONObject) o).getString("materialType");
            res.put("材料分类",getClfl(materialType));
            String OriginalRequired = ((JSONObject) o).getString("OriginalRequired");
            if(StringUtils.isBlank(OriginalRequired))
            {
                res.put("原件要求","");
            }
            res.put("原件要求" , OriginalRequired.equals("1")  ? "核验" : OriginalRequired.equals("2") ? "存档":"");
            String OriginalNumber = ((JSONObject) o).getString("OriginalNumber");
            OriginalNumber = OriginalNumber+"份";
            res.put("原件" , OriginalNumber);
            String form = ((JSONObject) o).getString("form");
            if(form.equals("1"))
            {res.put("材料形式","纸质");}
            if(form.equals("2"))
            {res.put("材料形式","电子");}
            if(form.equals("3"))
            {res.put("材料形式","纸质电子");}
            //"http://zwfw.hubei.gov.cn/web/lcfile/"
            String ExampleGuidPath = ((JSONObject) o).getString("ExampleGuidPath");
            if(!StringUtils.isBlank(ExampleGuidPath))
            {
                JSONObject handlingProceduresImage = new JSONObject();
                String orgImageUrl = "http://zwfw.hubei.gov.cn/web/lcfile/" + ExampleGuidPath;
                handlingProceduresImage.put("查看实例原地址", orgImageUrl);
                handlingProceduresImage.put("minio地址", downLoadFileUpLoadMinio(orgImageUrl, "办理地点地图.png"));
                res.put("查看实例", handlingProceduresImage);
            }
            else {res.put("查看实例","无");}
           String sourceType = ((JSONObject) o).getString("sourceType");
            if(StringUtils.isBlank(sourceType))
            {res.put("来源渠道","无");}
           else {res.put("来源渠道",getSourceType(sourceType));}
           String sourceExplain = ((JSONObject) o).getString("sourceExplain");
           if(StringUtils.isBlank(sourceExplain))
           {res.put("来源说明","无");}
           else {res.put("来源说明",sourceExplain);}
           String materialSpec = ((JSONObject) o).getString("materialSpec");
            if(StringUtils.isBlank(materialSpec))
            {res.put("材料规格","无");}
            else {res.put("材料规格",materialSpec);}
            String FillExplain = ((JSONObject) o).getString("FillExplain");
            if(StringUtils.isBlank(FillExplain))
            {res.put("填表须知","无");}
            else {res.put("填表须知",FillExplain);}
            String AcceptStand = ((JSONObject) o).getString("AcceptStand");
            if(StringUtils.isBlank(AcceptStand))
            {res.put("材料受理标准","无");}
            else {res.put("材料受理标准",AcceptStand);}
            object.put(alias,res);
            list.add(object);
        }
        NEW.put("文本",list);
        return NEW;
    }
    //获取材料分类
    private String getClfl(String clfl) {
        switch (clfl) {
            case "0":
                clfl = "申请表";
                break;
            case "1":
                clfl = "证明";
                break;
            case "2":
                clfl = "证照";
                break;
            case "3":
                clfl = "报告";
                break;
            case "4":
                clfl = "批文";
                break;
            case "9":
                clfl = "其他";
                break;
        }
        return clfl;
    }
    //获取来源渠道
    private String getSourceType(String type) {
        switch (type) {
            case "10":
                type = "申请人自备";
                break;
            case "20":
                type = "政府部门核发";
                break;
            case "99":
                type = "其他";
                break;
        }
        return type;
    }

    private JSONObject parseDetailxukeshoufei(){
        JSONObject res = new JSONObject();
        res.put("许可收费","无");
        return  res;
    }

    private JSONObject parseDetailzhongjiefuwu(String TransactCode){
        JSONObject res = new JSONObject();
        String detailUrl = "http://zwfw.hubei.gov.cn/web/bszn/ykypt/standard/transact/project/getTransactInfoByTransactCode.jspc";
        JSONObject detailparmas1 = new JSONObject();
        detailparmas1.put("transactCode", TransactCode);
        detailparmas1.put("type", "agent");
        String detailResponse = postFormReq(detailUrl, new JSONObject(), detailparmas1);
        JSONObject detailobj = JSONObject.parseObject(detailResponse);
        JSONArray detaillist = JSONArray.parseArray(detailobj.getString("data"));
        if(detaillist.size()>0) {
            for (Object o : detaillist) {
                String name = ((JSONObject) o).getString("name");
                String ServiceType = ((JSONObject) o).getString("ServiceType");
                String handle_url = ((JSONObject) o).getString("handle_url");
                String ServiceUrl = ((JSONObject) o).getString("ServiceUrl");
                if(StringUtils.isBlank(name)) {
                    if(StringUtils.isBlank(ServiceType))
                    {res.put("中介服务事项名称","");}
                    res.put("中介服务事项名称",ServiceType);
                }
                else
                {
                    res.put("中介服务事项名称",name);
                }

                if(StringUtils.isBlank(handle_url)) {
                    if(StringUtils.isBlank(ServiceUrl))
                    {res.put("中介服务查询网址","");}
                    res.put("中介服务查询网址",ServiceUrl);
                }
                else
                {
                    res.put("中介服务查询网址",handle_url);
                }

            }
        }
        return res;
    }

    private String fileDownloadAndUploadMinioGet(String url, String fileName) {
        try {
            JSONObject param = new JSONObject();
            JSONObject headers = new JSONObject();
            return DownloadAndUploadMinio.getInstance().downloadGet(
                    url,
                    headers,
                    param,
                    fileName
            );
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    public static  String downLoadFile(String strUrl, String fileName){
        // String strUrl = "http://zwfw.hubei.gov.cn//web/lcfile/group1/M00/00/4D/wKhUBF1VBAyAZ3OXAANoFLMh7QU722.jpg";
        try {
            //构造URL
            URL url = new URL(strUrl);
            //构造连接
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            //这个网站要模拟浏览器才行
            conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko");
            //打开连接
            conn.connect();
            //打开这个网站的输入流
            InputStream inStream = conn.getInputStream();
            //用这个做中转站 ，把图片数据都放在了这里，再调用toByteArray()即可获得数据的byte数组
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            //用这个是很好的，不用一次就把图片读到了文件中
            //要是需要把图片用作其他用途呢？所以直接把图片的数据弄成一个变量，十分有用
            //相当于操作这个变量就能操作图片了
            byte[] buf = new byte[1024];
            //为什么是1024？
            //1024Byte=1KB，分配1KB的缓存
            //这个就是循环读取，是一个临时空间，多大都没关系
            // 这没有什么大的关系，你就是用999这样的数字也没有问题，就是每次读取的最大字节数。
            //byte[]的大小，说明你一次操作最大字节是多少
            //虽然读的是9M的文件，其实你的内存只用1M来处理，节省了很多空间．
            //当然，设得小，说明I/O操作会比较频繁，I/O操作耗时比较长，
            // 这多少会有点性能上的影响．这看你是想用空间换时间，还是想用时间换空间了．
            //时间慢总比内存溢出程序崩溃强．如果内存足够的话，我会考虑设大点．
            int len = 0;
            //读取图片数据
            while ((len = inStream.read(buf)) != -1) {
                outStream.write(buf, 0, len);
            }
            inStream.close();
            outStream.close();
            //把图片数据填入文件中
            File file = new File(fileName);
            FileOutputStream op = new FileOutputStream(file);
            op.write(outStream.toByteArray());
            op.close();
        }catch (Exception e){
            e.printStackTrace();
        }
        return "";
    }

    public static  String downLoadFileUpLoadMinio(String strUrl, String fileName){
        // String strUrl = "http://zwfw.hubei.gov.cn//web/lcfile/group1/M00/00/4D/wKhUBF1VBAyAZ3OXAANoFLMh7QU722.jpg";
        try {
            //构造URL
            URL url = new URL(strUrl);
            //构造连接
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            //这个网站要模拟浏览器才行
            conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko");
            //打开连接
            conn.connect();
            //打开这个网站的输入流
            InputStream inStream = conn.getInputStream();
            String id = DownloadAndUploadMinio.getInstance().uploadFileToMinio(inStream, "chengdu", fileName);
            return id;
        }catch (Exception e){
            e.printStackTrace();
        }
        return "";
    }
    public static void main (String[] args) throws IOException {
        SpiderHB spiderHB = new SpiderHB();
        spiderHB.getDataDemo();
    }

}
